package thread.DQ;

import java.util.Iterator;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

public class LinkedBlockingDequeTest {
	
	public static void main(String[] args) {
		
		System.out.println("********** Start of LinkedBlockingDeque \n");
		BlockingDeque<String> deque = new LinkedBlockingDeque<String>();
		deque.addFirst("1");
		deque.add("3");
		deque.add("4");
		deque.add("5");
		deque.add("6");
		deque.add("7");
		// deque.addLast("2");
		try {
			
			System.out.print("LinkedBlockingDeque [ ");
			Iterator itr = deque.iterator();
			while (itr.hasNext()) {
				System.out.print(itr.next()+" ");
			}
			
			System.out.println("\nFirst - "+deque.takeFirst());
			System.out.println("Last - "+deque.takeLast());
			
			System.out.print("LinkedBlockingDeque [ ");
			itr = deque.iterator();
			while (itr.hasNext()) {
				System.out.print(itr.next()+" ");
			}
			
			System.out.println("\nFirst - "+deque.takeFirst());
			System.out.println("Last - "+deque.takeLast());
			
			System.out.print("LinkedBlockingDeque [ ");
			itr = deque.iterator();
			while (itr.hasNext()) {
				System.out.print(itr.next()+" ");
			}
			
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("\n\n********** End of LinkedBlockingDeque ");
		
	}
}
